home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / serverlib / disk / fastPath.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  4.7 KB  |  174 lines

  1. /*
  2.  *   $RCSfile: fastPath.c,v $  
  3.  *   $Revision: 1.1.1.1 $  
  4.  *   $Date: 1996/05/04 21:55:40 $      
  5.  */ 
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37. #include "sysdefs.h"
  38. #include "ess.h"
  39. #include "checking.h"
  40. #include "trace.h"
  41. #include "error.h"
  42. #include "list.h"
  43. #include "tid.h"
  44. #include "io.h"
  45. #include "lock.h"
  46. #include "object.h"
  47. #include "msgdefs.h"
  48. #include "disk.h"
  49. #include "thread.h"
  50. #include "semaphore.h"
  51. #include "latch.h"
  52. #include "link.h"
  53. #include "bf.h"
  54. #include "volume.h"
  55. #include "log.h"
  56. #include "lsn.h"
  57. #include "openlog.h"
  58. #include "threadstate.h"
  59. #include "thread_globals.h"
  60. #include "stat_globals.h"
  61. #include "msg_globals.h"
  62. #include "disk_funcs.h"
  63. #include "disk_globals.h"
  64. #include "../../diskproc/include/diskproc_extfuncs.h"
  65. #include "log_globals.h"
  66. #include "pool.h"
  67. #include "io_globals.h"
  68.  
  69. #define CHECK_THREAD_ERROR    \
  70.     SM_ASSERT(LEVEL_3, (Active->error == esmNOERROR &&        \
  71.                         Active->errno == esmNOERROR) ||        \
  72.                        (Active->error != esmNOERROR &&        \
  73.                         Active->errno != esmNOERROR))        
  74.  
  75.  
  76. /* the return value is 
  77.  * TRUE if all the i/o is done (by fast path),
  78.  * FALSE if the remote process has to do the work
  79.  */
  80. BOOL
  81. fastPath (
  82.     VOLREC    *volRec,
  83.     DISKMSG *message
  84. )
  85.  
  86. {
  87.     typedef void (*PFVD)(DISKMSG *);
  88.     PFVD func = (PFVD)0;
  89.  
  90.     switch( message->header.type ) {
  91.     case OPEN_DISK:
  92.         /* Special case:
  93.          * This MUST be done both locally and remotely,
  94.          * so we'll go ahead and do it, get the file
  95.          * descriptor, and then act as if we didn't do
  96.          * it locally.  That way it'll be done remotely as well.
  97.          */
  98.         Active->error = Active->errno = 0;
  99.         (void) openLocalDisk( message, volRec->volNameRec->volName.name );
  100.         volRec->fd = Fd;
  101.         CHECK_THREAD_ERROR;
  102.         Active->errno = (int)message->header.params.out.errno;
  103.         if ( FastPathOnly ) {
  104.             return TRUE;
  105.         } else  {
  106.             return FALSE; /* a lie for the server's normal operation */
  107.         }
  108.  
  109.     case CLOSE_DISK:
  110.         /* 
  111.          * Must be done both locally and remotely.
  112.          */
  113.         Fd = volRec->fd;
  114.         Active->error = Active->errno = 0;
  115.         (void) closeLocalDisk( message );
  116.         volRec->fd = -1;
  117.         CHECK_THREAD_ERROR;
  118.         Active->errno = (int)message->header.params.out.errno;
  119.         if ( FastPathOnly ) {
  120.             return TRUE;
  121.         } else  {
  122.             return FALSE; /* a lie for the server's normal operation */
  123.         }
  124.  
  125.     case READ_BLOCK:
  126.         func = readLocalDisk;
  127.         break;
  128.     case WRITE_BLOCK:
  129.         func = writeLocalDisk;
  130.         break;
  131.     case DUMP_MON:
  132.         func = dumpLocalProfiling;
  133.         break;
  134.     case FSYNC_DISK:
  135.         func = fsyncLocalDisk;
  136.         break;
  137.     default:
  138.         SM_ERROR(TYPE_FATAL, esmINTERNAL);
  139.         break;
  140.     }
  141.     /*
  142.      * Somewhat simplistic:
  143.      * do only if activity is such that it's apropos,
  144.      * namely, if all the activity is on one volume, or
  145.      * if there's only one client.
  146.      * TODO: Some day... figure out if there are any clients already
  147.      * waiting to be select()ed, by looking at ReadMask & ~DiskMask.
  148.      * (Keep in mind that they are BITVECs, not unsigned ints.)
  149.      *
  150.      * FastPathOnly is TRUE when : this is formatvol, and when
  151.      * this is the server pre-mounting volumes (no clients yet).
  152.      */
  153.     if(    FastPathOnly || 
  154.         (   ( NumActiveClients <= 1 )  &&
  155.             !(OpenLog.flags & LOG_CHECKPOINT_IN_PROGRESS) &&
  156.             PreventFastPath == 0 ) )    {
  157.  
  158.         SM_ASSERT(LEVEL_1, (func != (PFVD)0) );
  159.  
  160.         /* do fast path */
  161.         Fd = volRec->fd;
  162.         Active->error = Active->errno = 0;
  163.         (void) (*func)( message );
  164.         CHECK_THREAD_ERROR;
  165.         Active->errno = (int)message->header.params.out.errno;
  166.         return TRUE;
  167.     } else {
  168.  
  169.         /* remote i/o */
  170.         Active->errno = (int)message->header.params.out.errno;
  171.         return FALSE;
  172.     }
  173. }
  174.